import java.util.Arrays;

public class MyArrayList {
    private int [] elem;
    private int usedSize;
    public MyArrayList(){
        this.elem=new int[10];
    }

    public void display(){
        for (int i = 0; i <this.usedSize ; i++) {
            System.out.print(this.elem[i]+" ");
        }
    }

    public boolean isFull(){
        if(this.usedSize==this.elem.length){
            return true;
        }
        return false;
    }
    public void add(int data){
        if(isFull()){
            this.elem= Arrays.copyOf(this.elem,2*this.elem.length);
        }
        this.elem[this.usedSize]=data;
        this.usedSize++;
    }
    public void add(int pos, int data){
       if(pos<0||pos>this.usedSize){
           throw new PosOutOfBoundsException("位置不合法");
       }
       if(isFull()){
           this.elem= Arrays.copyOf(this.elem,2*this.elem.length);
       }
        for (int i = this.usedSize-1; i >=pos ; i--) {
            this.elem[i+1]=this.elem[i];
        }
        this.elem[pos]=data;
        this.usedSize++;
    }

    public boolean contains(int toFind){
        for (int i = 0; i <this.elem.length ; i++) {
            if(this.elem[i]==toFind)
                return true;
        }
        return false;
    }

    public int indexOf(int data){
        for (int i = 0; i <this.elem.length ; i++) {
            if(this.elem[i]==data)
                return i;
        }
        return -1;
    }
    public int size(){
        return this.usedSize;
    }

    public void clear(){
        this.usedSize=0;
    }

    public int get(int pos){
        if(pos<0||pos>=this.usedSize){
            throw new PosOutOfBoundsException("位置不合法");
        }
        return this.elem[pos];
    }

    public void set(int pos,int data){
        if(pos<0||pos>=this.usedSize){
            throw new PosOutOfBoundsException("位置不合法");
        }
        this.elem[pos]=data;
    }

    public void reMove(int toMove){
        int pos =indexOf(toMove);
        if(pos==-1){
            System.out.println("没有这个数");
        }

        for (int i = pos; i <this.usedSize-1; i++) {
            this.elem[i]=this.elem[i+1];
        }
        this.usedSize--;
    }
}